#define _CRT_SECURE_NO_WARNINGS 1

#include"sort.h"

int count = 0;

void TestQueue()
{
	Queue* Q = QueueInit();
	QueuePush(Q, 1);
	QueuePush(Q, 2);
	QueuePush(Q, 3);
	QueuePush(Q, 4);
	QueuePush(Q, 5);

	while (!QueueEmpty(Q))
	{
		printf("%d ", QueueRead(Q));
		QueuePop(Q);
	}
	QueueDestroy(Q);
}

void TestStack()
{
	Stack* ST = StackInit();
	StackPush(ST, 1);
	StackPush(ST, 2);
	StackPush(ST, 3);
	StackPush(ST, 4);
	StackPush(ST, 5);
	while (!StackEmpty(ST))
	{
		printf("%d ", StackRead(ST));
		StackPop(ST);
	}

	StackDestroy(ST);
}

int* Creat()
{
	int N = NUM;
	int* arr = (int*)malloc(sizeof(int) * N);
	if (arr == NULL)
	{
		perror("malloc erroe");
		exit(-1);
	}
	int size = N;
	for (int i = 0; i < N; i++)
	{
		arr[i] = rand() % 10000;
	}
	return arr;
}


void test()
{
	int size = 10;
	int arr[] = { 9,6,3,8,5,2,7,4,1,0 };
	QuickSortNonr_Queue(arr, size);
	SortPrint(arr, size);
}

void TestTime()
{
	int* arr1 = Creat();
	int* arr2 = Creat();
	int* arr3 = Creat();
	int* arr4 = Creat();
	int* arr5 = Creat();
	int* arr6 = Creat();
	int* arr7 = Creat();
	int* arr8 = Creat();
	int* arr9 = Creat();
	int* arr10 = Creat();
	int* arr11 = Creat();
	int clock1 = clock();
	int size = NUM;
	ShellSort(arr1, size);
	int clock2 = clock();
	HeapSort(arr2, size);
	int clock3 = clock();
	//InsertSort(arr3, size);
	int clock4 = clock();
	QuickSort(arr4, 0, size - 1);
	int clock5 = clock();
	//BubbleSort(arr5, size);
	int clock6 = clock();
	//SelectSort(arr6, size);
	int clock7 = clock();
	MergeSort(arr7, size);
	int clock8 = clock();
	MergeSortNonr(arr8, size);
	int clock9 = clock();
	//CountSort(arr9, size);
	int clock10 = clock();
	QuickSortNonr_Stack(arr10, size);
	int clock11 = clock();
	QuickSortNonr_Queue(arr11, size);
	int clock12 = clock();
	free(arr1);
	free(arr2);
	free(arr3);
	free(arr4);
	free(arr5);
	free(arr6);
	free(arr7);
	free(arr8);
	free(arr9);
	free(arr10);
	free(arr11);
	printf("ShellSort:%d ms\n", clock2 - clock1);
	printf("HeapSort:%d ms\n", clock3 - clock2);
	printf("InsertSort:%d ms\n", clock4 - clock3);
	printf("QuickSort:%d ms\n", clock5 - clock4);
	printf("QuickSortNonr_Stack:%d ms\n", clock11 - clock10);
	printf("QuickSortNonr_Queue:%d ms\n", clock12 - clock11);
	printf("BubbleSort:%d ms\n", clock6 - clock5);
	printf("SelectSort:%d ms\n", clock7 - clock6);
	printf("MergeSort:%d ms\n", clock8 - clock7);
	printf("MergeSortNonr:%d ms\n", clock9 - clock8);
	//printf("CountSort:%d ms\n", clock10 - clock9);
	//printf("%d\n", count);
}

int main()
{
	srand((unsigned int)time(0));
	
	//TestQueue();
	//TestStack();
	TestTime();
	//test();
	return 0;
}